﻿using System;
using Player;
using ScriptObject.Weapon;
using UnityEngine;

public class WeaponPickComp : MonoBehaviour
{
    private BoxCollider boxCollider;
    public string prefabId;
    public WeaponBaseAttribute weaponBaseAttribute;

    private void Awake()
    {
        boxCollider = GetComponent<BoxCollider>();
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            boxCollider.enabled = false;
            BackpackComp backpackComp = other.transform.GetComponent<BackpackComp>();
            WeaponInstanceData weaponInstanceData = new WeaponInstanceData();
            weaponInstanceData.prefabId = prefabId;
            weaponInstanceData.weaponBaseAttribute = weaponBaseAttribute;
            weaponInstanceData.createdTime = DateTime.Now;
            // 组装武器数据 放入背包
            backpackComp.weaponList.Add(weaponInstanceData);
            Destroy(gameObject);
        }
    }
}